<?php
	if (!defined('BASEPATH'))
		exit('No direct script access allowed');

	class VendorSignup extends CI_Controller
	{
		public $error_code = 0;
		public $result_message = '';
		public $email_message = '';
		public $confirm_email_message = '';
		public $confirm_password_message = '';

		public function index()
		{
			$data = array(
				'error_code' => 0,
				'result_message' => '',
				'email_message' => '',
				'confirm_email_message' => '',
				'confirm_password_message' => '',
			);
			$this->load->view('v_vendorsignup', $data);
		}

		public function addUser()
		{
			$error_code = 0;
			$email_message = '';
			$confirm_email_message = '';
			$confirm_password_message = '';
			$result_message = '';

			if ($_POST['Email'] != $_POST['ConfirmEmail'])
			{
				$error_code = -1000;
				$confirm_email_message = 'email validation failed';
			}
			else if ($_POST['CreatePassword'] != $_POST['ConfirmPassword'])
			{
				$error_code = -2000;
				$confirm_password_message = 'password validation failed';
			}
			else
			{
				$this->load->model('m_vendorsignup');
				$error_code = $this->m_vendorsignup->add_user($_POST['Email'], $_POST['CreatePassword']);
				
				if ($error_code == 0)
				{
					$result_message = 'successfully added';
				}
				else if ($error_code == -1)
				{
					$email_message = 'user already exists, pick something else';
				}
				// change to a switch state if there are more than 2 error codes...

			}

			$data = array(
				'error_code' => $error_code,
				'result_message' => $result_message,
				'email_message' => $email_message,
				'confirm_email_message' => $confirm_email_message,
				'confirm_password_message' => $confirm_password_message,
			);
			$this->load->view('v_vendorsignup', $data);
		}
	}
?>
